package jk.spider.core.throttle;

import jk.spider.core.throttle.impl.DistributeLoadThrottleProvider;
import jk.spider.util.config.ConfigConstants;
import jk.spider.util.config.MappedPropertySet;
import jk.spider.util.config.PropertySet;

import org.apache.log4j.Logger;

public class ThrottleFactory {
	private static final Logger log = Logger.getLogger(ThrottleFactory.class);
	public Throttle createThrottle(PropertySet props) {
        PropertySet throttleProps = new MappedPropertySet ( ConfigConstants.CONFIG_THROTTLE, props );
        Class providerClass = throttleProps.getClass(ConfigConstants.THROTTLE_PROVIDER, DistributeLoadThrottleProvider.class);
        try {
        	ThrottleProvider provider = (ThrottleProvider) providerClass.newInstance();
        	return provider.createThrottle(throttleProps);
        } catch (InstantiationException e) {
        	log.error("InstantiationException on Throttle", e);
            return null;
        } catch (IllegalAccessException e) {
            log.error("IllegalAccessException on Throttle", e);
            return null;
        }
	}
}
